package game.efekti;

import util.INIGroup;
import util.Util;
import game.Character;
import game.DamageType;
import game.EffectStage;
import game.MagicEffect;
import game.Item.ItemType;

public class ElementalDamage extends MagicEffect {
	int minDamage;
	int maxDamage;
	DamageType tip;

	@Override
	public EffectStage getStage() {
		return EffectStage.TargetOnStrike;
	}

	@Override
	public boolean canHazTip(ItemType tip) {
		return tip.equals(ItemType.WEAPON);
	}

	@Override
	public void doEffect(Character caster, Character target) {
		target.SufferDamage(Util.getRndInt(this.minDamage, this.maxDamage), this.tip,caster);
	}

	@Override
	public String toString() {
		String ret;
		ret = this.minDamage + "-" + this.maxDamage + " " + this.tip.toString().toLowerCase() + " damage";
		return ret;
	}

	@Override
	public void generateForLevel(int lvl) {
		int tipDmg = Util.getRndInt(0, 3);		
		switch (tipDmg){
		case 0:
			this.tip = DamageType.Cold;
			this.minDamage = Util.getRndInt(1, lvl/4+4);
			this.maxDamage = Util.getRndInt(this.minDamage, lvl*2+4);
			break;
		case 1: 
			this.tip = DamageType.Fire;
			this.minDamage = Util.getRndInt(1, lvl/4+4);
			this.maxDamage = Util.getRndInt(this.minDamage, lvl*2+4);
			break;
		case 2: 
			this.tip = DamageType.Lightning;
			this.minDamage = Util.getRndInt(1, lvl/4+4);
			this.maxDamage = Util.getRndInt(this.minDamage, lvl*2+4);
			break;
		case 3: 
			this.tip = DamageType.Physical;
			this.minDamage = Util.getRndInt(1, lvl/4+4);
			this.maxDamage = Util.getRndInt(this.minDamage, lvl*2+4);
			break;
		}

	}

	@Override
	public boolean loadFromFile(INIGroup grupa) {
		tag = grupa.getString("Tag");
		tip = DamageType.valueOf(grupa.getString("DamageType", "Fire"));
		minDamage = grupa.getInteger("Min", 0);
		maxDamage = grupa.getInteger("Max", 0);
		return true;
	}

	@Override
	public void init() {}

	@Override
	public boolean stacksWith(MagicEffect e) {
		if(e instanceof ElementalDamage)
			return ((ElementalDamage)e).tip == tip;
		return false;
	}

	@Override
	public void absorb(MagicEffect e) {
		if(stacksWith(e))
		{
			minDamage += ((ElementalDamage)e).minDamage;
			maxDamage += ((ElementalDamage)e).maxDamage;
		}
	}

}
